package cn.com.headfree.qynj.util;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;

/**  
 * @Title  HttpClientUtils.java   
 * @Package com.headfree.utils   
 * @Description httpclient工具类
 * @author yangwang 
 * @date  2020年7月21日 下午2:30:42   
 */
public class HttpClientUtils {
	
	
	@SuppressWarnings({ "deprecation", "resource" })
	private static HttpResponse httpClientCall(HttpPost httpPost) throws ClientProtocolException, IOException {
		HttpClient client = new DefaultHttpClient();
		client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,HttpVersion.HTTP_1_1);  
        client.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "utf-8");
        
        return client.execute(httpPost);
	}
	
	@SuppressWarnings("unused")
	public static HttpResponse httpPostCall(String requestUrl,HttpEntity httpEntity) throws ClientProtocolException, IOException {
		HttpPost httpPost = new HttpPost(requestUrl);
		//模拟浏览器
		httpPost.addHeader( "User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
		httpPost.setEntity(httpEntity);
		
		return httpClientCall(httpPost);
	}

}
